 package com.su.song.shapapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;

import java.util.Calendar;

 public class Shap3Activity extends AppCompatActivity implements View.OnClickListener, DatePickerDialog.OnDateSetListener {

     private DatePicker dp_pulley;
     private TextView date_show;
     private int year;
     private int month;
     private int d2;

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shap3);


        dp_pulley = findViewById(R.id.DP_pulley);
        date_show = findViewById(R.id.date_show);
        findViewById(R.id.btn_pulley).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String desc = String.format("您选择的日期：%d年%d月%d日",dp_pulley.getYear(),dp_pulley.getMonth()+1,dp_pulley.getDayOfMonth());
                date_show.setText(desc);
            }
        });

        findViewById(R.id.btn_calendar).setOnClickListener(this);

//        findViewById(R.id.btn_calendar).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });
    }

     @Override
     public void onClick(View v) {
         //获取当前时间的年月日
                Calendar calendar =Calendar.getInstance();
                year = calendar.get(Calendar.YEAR);
                month = calendar.get(Calendar.MONTH);
                d2 = calendar.get(Calendar.DAY_OF_MONTH);
         DatePickerDialog dialog = new DatePickerDialog(this,this,year,month,d2);
                dialog.show();

     }

     @Override
     public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
         String desc = String.format("您选择的日期：%d年%d月%d日",year,month,d2);
         date_show.setText(desc);
     }
 }